import { map } from 'unist-util-map';
import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
import { createCommentNode } from './createCommentNode.js';
const rehypeMdxRemoveUnknownJsx = (options) => (tree) => {
    const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
    return map(tree, (node) => {
        var _a;
        if (isMdxJsxFlowElementHast(node)) {
            if (node.name &&
                !((_a = options.allowedComponents) === null || _a === void 0 ? void 0 : _a.includes(node.name)) &&
                !exportedComponentNames.includes(node.name)) {
                return createCommentNode(node.name);
            }
        }
        return node;
    });
};
export default rehypeMdxRemoveUnknownJsx;
